class Solution {
    public int uniquePathsWithObstacles(int[][] obstacleGrid) {
        int m = obstacleGrid.length;
        int n = obstacleGrid[0].length;
        //1.建表
        int[][] dp = new int[m][n];

        //2.初始化
        if(obstacleGrid[0][0] == 0) dp[0][0] = 1;

        //3.填表
        for(int i = 0; i < m; i++) {
            for(int j = 0; j < n; j++) {
                if(i-1 >= 0 && obstacleGrid[i][j] == 0) {
                    dp[i][j] += dp[i-1][j];
                }
                if(j-1 >= 0 && obstacleGrid[i][j] == 0) {
                    dp[i][j] += dp[i][j-1];
                }
            }
        }

        //4.返回值
        return dp[m-1][n-1];
    }
}
